HAL RTC Typical use cases for migration

This section provides information about the HAL RTC Typical use cases for migration.

HAL RTC calendar

The main purpose of this use case is to configure the RTC calendar by setting the time and date, enabling accurate timekeeping for the application.

HAL1 Sequence Diagrams

HAL2 Sequence Diagrams

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc

== RTC initialization ==
app -> rtc : HAL_RTC_Init()
rtc --> app : HAL_OK

|||
|||
|||
|||
|||
|||

== Calendar initialization ==
|||
|||
|||
|||
app -> rtc : HAL_RTC_SetTime()
rtc --> app : HAL_OK

app -> rtc : HAL_RTC_SetDate()
rtc --> app : HAL_OK


@enduml

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc

== RTC initialization ==

app -> rtc : HAL_RTC_DisableWriteProtection()
rtc --> app : HAL_OK

app -> rtc : HAL_RTC_EnterInitMode()
rtc --> app : HAL_OK

group Optional [Set the RTC prescalers values and the RTC mode]
app -> rtc: HAL_RTC_SetConfig(&p_config)
rtc --> app: HAL_OK
end

== Calendar initialization in BCD or mixed mode ==

group Optional [Set the bypass shadow registers and calendar hour format]
app -> rtc : HAL_RTC_CALENDAR_SetConfig(&p_config_calendar)
rtc -> app : HAL_OK
end

group Set time and date [choice 1]
    app -> rtc : HAL_RTC_CALENDAR_SetTime(&p_time)
    rtc --> app : HAL_OK

    app -> rtc : HAL_RTC_CALENDAR_SetDate(&p_date)
    rtc --> app : HAL_OK
end

group Set time and date [choice 2]
    app -> rtc : HAL_RTC_CALENDAR_SetDateTime(&p_date, &p_time)
    rtc --> app : HAL_OK
end


@enduml

HAL RTC calendar use case

HAL1 Example

HAL2 Example

RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};

/** Initialize RTC Only */
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
hrtc.Init.SynchPrediv = RTC_SYNCH_PREDIV;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
hrtc.Init.BinMode = RTC_BINARY_NONE;

HAL_RTC_Init(&hrtc)









/** Initialize RTC and set the Time and Date */
sTime.Hours = 0x2;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;

HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD)

sDate.WeekDay = RTC_WEEKDAY_FRIDAY;
sDate.Month = RTC_MONTH_NOVEMBER;
sDate.Date = 0x6;
sDate.Year = 0x25;

HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD)
hal_rtc_config_t rtc_config;
hal_rtc_calendar_config_t rtc_calendar_config;

/* RTC and TAMP kernel clock enable */
HAL_RCC_RTC_SetKernelClkSource(HAL_RCC_RTC_CLK_SRC_LSE);
HAL_RCC_RTC_EnableKernelClock();

/* RTC and TAMP APB clock enable */
HAL_RCC_RTCAPB_EnableClock();

HAL_RTC_DisableWriteProtection();

HAL_RTC_EnterInitMode();

rtc_config.asynch_prediv = 0x7F;
rtc_config.synch_prediv = 0x00FF;
rtc_config.mode = HAL_RTC_MODE_BCD;
rtc_config.seconds_update = HAL_RTC_BCD_UPDATE_8BITS;

HAL_RTC_SetConfig(&rtc_config)

rtc_calendar_config.hour_format = HAL_RTC_CALENDAR_HOUR_FORMAT_24;
rtc_calendar_config.bypass_shadow_register = HAL_RTC_CALENDAR_SHADOW_REG_KEEP ;

HAL_RTC_CALENDAR_SetConfig(&rtc_calendar_config)

RtcTime.am_pm = HAL_RTC_TIME_FORMAT_AM_24H;
RtcTime.subsec = 0U;
RtcTime.microsec = 0U;
RtcTime.millisec = 0U;
RtcTime.hour = 2U;
RtcTime.min = 0U;
RtcTime.sec = 0U;

RtcDate.wday = HAL_RTC_WEEKDAY_FRIDAY ;
RtcDate.mon = HAL_RTC_MONTH_NOVEMBER ;
RtcDate.mday = 6U;
RtcDate.year = 25U;

HAL_RTC_CALENDAR_SetDateTime(&RtcDate, &RtcTime)

HAL RTC output

The main purpose of this use case is to configure and manage the RTC output signals, including tampalarm and calibration outputs, and to enable or disable the RTC output as required by the application.

HAL1 Sequence Diagrams

HAL2 Sequence Diagrams

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc

== RTC initialization ==
app -> driv: HAL_RTC_Init()
driv --> app

|||
|||
|||

== Output calibration configuration and enable ==
app -> rtc : HAL_RTCEx_SetCalibrationOutPut(&hrtc, CalibOutput)
rtc --> app : HAL_OK
|||
|||
|||
|||
|||
|||
|||
|||
|||
== Disable output ==
app -> rtc : HAL_RTCEx_DeactivateCalibrationOutPut(&hrtc)
rtc --> app : HAL_OK

@enduml

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc

== RTC initialization ==
app -> rtc : HAL_RTC_DisableWriteProtection()
rtc --> app : HAL_OK

app -> rtc : HAL_RTC_EnterInitMode()
rtc --> app : HAL_OK

== Output tampalarm configuration ==
app -> rtc : HAL_RTC_OUTPUT_SetConfigTampalarm(&p_config)
rtc --> app : HAL_OK

== Output calibration configuration ==
app -> rtc : HAL_RTC_OUTPUT_SetConfigCalib(&p_config)
rtc --> app : HAL_OK

== Enable output ==
app -> rtc: HAL_RTC_OUTPUT_Enable(output)
rtc --> app : HAL_OK

== Disable output ==
app -> rtc : HAL_RTC_OUTPUT_Disable()
rtc --> app : HAL_OK

@enduml

Related examples in HAL2

Example Name

Description

example_hal_rtc_calib_output_frequency

Configuration of the calibration output frequency using the RTC HAL API. This example guides you through the different configuration steps by means of the RTC HAL API to configure a calibration output frequency. How to configure calibration output frequency using the RTC HAL API


HAL RTC alarm

The main purpose of this use case is to configure and manage the RTC alarm functionality, allowing the application to set alarms and handle alarm events using either interrupt mode or polling mode.

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc
participant "Interruption" as int

== RTC initialization ==
app -> driv: HAL_RTC_Init()
driv --> app

== Alarm initialization ==
app -> rtc : HAL_RTC_SetTime(alarm, &sTime, RTC_FORMAT_BCD)
rtc --> app : HAL_OK
app -> rtc : HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD)
rtc --> app : HAL_OK

group Interruption mode
== Start Alarm IT ==
app -> rtc : HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD)
rtc --> app : HAL_OK

== Alarm timer IRQ handler ==
int -> rtc : HAL_RTC_AlarmIRQHandler()

== Alarm callback ==
rtc -> app : HAL_RTC_AlarmAEventCallback(&hrtc)
app --> rtc
end


group Polling mode
== Start Alarm ==
app -> rtc : HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BCD)
rtc --> app : HAL_OK

== Poll for alarm events ==
app -> rtc: HAL_RTC_PollForAlarmAEvent(hrtc, timeout)
rtc --> app: HAL_OK

end

== Alarm stop ==
app -> rtc: HAL_RTC_DeactivateAlarm(hrtc, alarm)
rtc --> app : HAL_OK

@enduml

HAL RTC alarm use case

HAL1 Example

HAL2 Example

RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
RTC_AlarmTypeDef sAlarm = {0};

/** Initialize RTC Only */
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
hrtc.Init.SynchPrediv = RTC_SYNCH_PREDIV;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
hrtc.Init.BinMode = RTC_BINARY_NONE;

HAL_RTC_Init(&hrtc);


/** Initialize RTC and set the Time and Date */
sTime.Hours = 0x2;
sTime.Minutes = 0x20;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);

sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_DECEMBER;
sDate.Date = 0x7;
sDate.Year = 0x20;
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);

/** Enable the Alarm A */
sAlarm.AlarmTime.Hours = 0x2;
sAlarm.AlarmTime.Minutes = 0x20;
sAlarm.AlarmTime.Seconds = 0x30;
sAlarm.AlarmTime.SubSeconds = 0x56;
sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;
sAlarm.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY;
sAlarm.Alarm = RTC_ALARM_A;

HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD);
hal_rtc_config_t rtc_config;
hal_rtc_calendar_config_t rtc_calendar_config;
hal_rtc_time_t rtc_time;
hal_rtc_date_t rtc_date;
hal_rtc_alarm_config_t alarm_config;
hal_rtc_alarm_date_time_t alarm_date_time_config;

/* Peripheral clock enable */
HAL_RCC_RTC_SetKernelClkSource(HAL_RCC_RTC_CLK_SRC_LSE);
HAL_RCC_RTC_EnableKernelClock();
HAL_RCC_RTCAPB_EnableClock();

HAL_RTC_DisableWriteProtection();
HAL_RTC_EnterInitMode();

rtc_config.asynch_prediv = 0x7F;
rtc_config.synch_prediv = 0x00FF;
rtc_config.mode = HAL_RTC_MODE_BCD;
rtc_config.seconds_update = HAL_RTC_BCD_UPDATE_8BITS;

HAL_RTC_SetConfig(&rtc_config)

HAL_RTC_ExitInitMode();
HAL_RTC_EnableWriteProtection();

alarm_config.auto_clear = HAL_ALARM_AUTO_CLEAR_DISABLE;
alarm_config.subsec_auto_reload = HAL_RTC_ALARM_SUBSECONDS_AUTO_RELOAD_DISABLE;

HAL_RTC_ALARM_SetConfig(HAL_RTC_ALARM_A, &alarm_config)

alarm_date_time_config.time.hour = 2U;
alarm_date_time_config.time.min = 20U;
alarm_date_time_config.time.sec = 30U;
alarm_date_time_config.time.subsec = 56U;
alarm_date_time_config.time.microsec = 0U;
alarm_date_time_config.time.millisec = 0U;
alarm_date_time_config.time.am_pm = HAL_RTC_TIME_FORMAT_AM_24H;
alarm_date_time_config.mask = HAL_RTC_ALARM_MASK_NONE;
alarm_date_time_config.subsec_mask = 0U;
alarm_date_time_config.mday_wday_selection = HAL_RTC_ALARM_DAY_TYPE_SEL_WEEKDAY;
alarm_date_time_config.wday_mday.wday = HAL_RTC_WEEKDAY_MONDAY ;

HAL_RTC_ALARM_SetDateTime(HAL_RTC_ALARM_A, &alarm_date_time_config)

/* Starts RTC alarm A in interrupt mode */
HAL_RTC_ALARM_Start(HAL_RTC_ALARM_A, HAL_RTC_ALARM_IT_ENABLE);

Related examples in HAL2

Example Name

Description

example_hal_rtc_alarm

Configuration and generation of an RTC alarm using the RTC HAL API. This example guides you through the different configuration steps by means of the RTC HAL API to configure and generate an RTC alarm.How to configure and generate an RTC alarm using the RTC HAL API.


HAL RTC timestamp

HAL RTC timestamp enable pin source

The main purpose of this use case is to configure and manage the RTC timestamp functionality, allowing the application to capture and retrieve the exact time and date of specific events. This can be achieved using either interrupt mode or polling mode, depending on the application’s requirements.

@startuml

participant "User Application" as app
participant "HAL Real Time Clock Driver" as rtc
participant "Interruption" as int

== Set time and date ==
app -> rtc : HAL_RTC_SetTime(alarm, &sTime, RTC_FORMAT_BCD)
rtc --> app : HAL_OK
app -> rtc : HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD)
rtc --> app : HAL_OK

group Interruption Mode
== Timestamp configuration and enable pin source ==
app -> rtc: HAL_RTCEx_SetTimeStamp_IT(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT)
rtc --> app : HAL_OK

== Timestamp interruption and IRQ handler ==
int -> rtc : HAL_RTC_TIMESTAMP_IRQHandler(&hrtc)

== Timestamp callback ==
rtc -> app : HAL_RTCEx_TimeStampEventCallback(&hrtc)
app --> rtc

== Retrieve timestamp value ==
app -> rtc: HAL_RTCEx_GetTimeStamp(&hrtc, &sTimeStampget, &sTimeStampDateget, RTC_FORMAT_BIN)
rtc --> app: HAL_OK
end

group Polling Mode
== Timestamp configuration and enable pin source ==
app -> rtc: HAL_RTCEx_SetTimeStamp(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT)
rtc --> app : HAL_OK

== Retrieve timestamp event ==
app -> rtc: HAL_RTCEx_PollForTimeStampEvent(&hrtc, Timeout)
rtc --> app: HAL_OK

app -> rtc: HAL_RTCEx_GetTimeStamp(&hrtc, &sTimeStampget, &sTimeStampDateget, RTC_FORMAT_BIN)
rtc --> app: HAL_OK

end


@enduml

HAL RTC timestamp enable internal source

The main purpose of this use case is to configure and manage the RTC timestamp functionality, including enabling internal and external timestamp sources. It allows the application to capture and retrieve the exact time and date of specific events using either interrupt mode or polling mode, depending on the application’s requirements.

@startuml

participant "User Application" as app
participant "HAL Real Time Clock Driver" as rtc
participant "Interruption" as int

== Timestamp Configuration and enable ==

app -> rtc : HAL_RTCEx_SetInternalTimeStamp(&hrtc)
rtc --> app : HAL_OK

group Interruption Mode
== Timestamp configuration and enable pin source ==
app -> rtc: HAL_RTCEx_SetTimeStamp_IT(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT)
rtc --> app : HAL_OK

== Timestamp interruption and IRQ handler ==
int -> rtc : HAL_RTC_TIMESTAMP_IRQHandler(&hrtc)

== Timestamp callback ==
rtc -> app : HAL_RTCEx_TimeStampEventCallback(&hrtc)
app --> rtc

== Retrieve timestamp value ==
app -> rtc: HAL_RTCEx_GetTimeStamp(&hrtc, &sTimeStampget, &sTimeStampDateget, RTC_FORMAT_BIN)
rtc --> app: HAL_OK
end

group Polling Mode
== Timestamp configuration and enable pin source ==
app -> rtc: HAL_RTCEx_SetTimeStamp(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT)
rtc --> app : HAL_OK

== Retrieve timestamp event ==
app -> rtc: HAL_RTCEx_PollForTimeStampEvent(&hrtc, Timeout)
rtc --> app: HAL_OK

app -> rtc: HAL_RTCEx_GetTimeStamp(&hrtc, &sTimeStampget, &sTimeStampDateget, RTC_FORMAT_BIN)
rtc --> app: HAL_OK

end

@enduml

Related examples in HAL2

Example Name

Description

example_hal_rtc_timestamp

Configuration of the RTC HAL API to demonstrate the timestamp feature.This example guides you through the different configuration steps by means of the RTC HAL API to demonstrate the timestamp feature.

example_hal_rtc_timestamp_tamper_source

Configuration of the timestamp tamper source using the RTC HAL API. This example guides you through the different configuration steps by means of the RTC HAL API to configure a timestamp tamper source.How to configure timestamp tamper source using the RTC HAL API.


HAL RTC wake-up timer

The main purpose of this use case is to configure and manage the RTC wakeup timer, enabling the application to wake up periodically from low-power modes. The wakeup timer can be used in either interrupt mode or polling mode.

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc
participant "Interruption" as int

== RTC initialization ==
app -> rtc: HAL_RTC_Init()
rtc --> app

group interruption mode
== Start wakeup timer ==
app -> rtc : HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, WakeUpCounter, WakeUpClock, WakeUpAutoClr)

== Wake up timer IRQ handler ==
int -> rtc : HAL_RTCEx_WakeUpTimerIRQHandler(void)

== Wake up callback ==
rtc -> app : HAL_RTCEx_WakeUpTimerEventCallback
app --> rtc
end

group Polling mode
== Start wakeup timer ==
app -> rtc : HAL_RTCEx_SetWakeUpTimer(&hrtc, WakeUpCounter, WakeUpClock)
rtc --> app :

== Wake up timer event ==
app -> rtc : HAL_RTCEx_PollForWakeUpTimerEvent(&hrtc, timeout)
rtc --> app: HAL_OK
end

== Stop wakeup timer ==
app -> rtc : HAL_RTCEx_DeactivateWakeUpTimer(&hrtc)
rtc --> app : HAL_OK

@enduml

Related examples in HAL2

Example Name

Description

example_hal_rtc_wakeup_timer_from_standby

How to periodically enter and wake up from STANDBY mode thanks to the RTC Wake-Up Timer (WUT).


Note

For the TAMPER use cases, you can find the dedicated functions in the TAMP Driver.

This change is due to the specific concept to separate the RTC and TAMP drivers: Other HAL RTC changes

HAL TAMPER passive tampers

 @startuml

 participant Application as app
 participant "RTC Driver" as tamp
 participant "Interruption" as int

 group Interruption mode

 == Configuration and start of passive tamper ==
     app -> tamp : HAL_RTCEx_SetTamper_IT(&hrtc, &sTamper)
     tamp --> app : HAL_OK

 == Tamp IRQ handler ==
     int -> tamp : HAL_RTCEx_TamperIRQHandler()

 == Tamp callback ==
     tamp -> app : HAL_RTCEx_Tamper1EventCallback()
     app --> tamp

end


 group Polling mode

 == Configuration and start of passive tamper ==
     app -> tamp : HAL_RTCEx_SetTamper(&hrtc, &sTamper)
     tamp --> app : HAL_OK

 == Poll tamper event ==
     app -> tamp: HAL_RTCEx_PollForTamperEvent(&hrtc, Tamper, Timeout)
     tamp --> app : HAL_OK

 end

 == Stop the passive tampers ==

     app -> tamp : HAL_RTCEx_DeactivateTamper(&hrtc, Tampers)
     tamp --> app: HAL_OK

 @enduml


HAL TAMPER internal tampers

@startuml

participant Application as app
participant "RTC Driver" as tamp
participant "Interruption" as int

group Interruption mode

== Configuration and start of internal tampers ==
    app -> tamp : HAL_RTCEx_SetInternalTamper_IT(&hrtc, sIntTamper)
    tamp --> app : HAL_OK

== Tamp IRQ handler ==
    int -> tamp : HAL_RTCEx_TamperIRQHandler()

== Tamper internal callback ==
    tamp -> app : HAL_RTCEx_InternalTamper1EventCallback()
    app --> tamp
end



group Polling mode

== Configuration and start of internal tampers ==
    app -> tamp : HAL_RTCEx_SetInternalTamper(&hrtc, sIntTamper)
    tamp --> app : HAL_OK

== Poll internal tamper event ==
    app -> tamp: HAL_RTCEx_PollForInternalTamperEvent(&hrtc, IntTamper, Timeout)
    tamp --> app : HAL_OK

end

== Stop the internal tampers ==

    app -> tamp : HAL_RTCEx_DeactivateInternalTamper(&hrtc, IntTamper)
    tamp --> app: HAL_OK

@enduml


HAL TAMPER active tampers

@startuml

participant Application as app
participant "RTC Driver" as tamp
participant "Interruption" as int

    group Interruption mode

== Configuration and start of active tampers ==

    app -> tamp : HAL_RTCEx_SetActiveTampers(&hrtc, &sTamper1)
    note right
    Pass "RTC_ATAMP_INTERRUPT_ENABLE" as an argument in the "RTC_ActiveTampersTypeDef" structure.
    end note
    tamp --> app : HAL_OK

== Set the seeds ==

    app -> tamp : HAL_RTCEx_SetActiveSeed(&hrtc, &p_values)
    tamp --> app: HAL_OK

== Tamper IRQ handler ==

    int -> tamp : HAL_RTCEx_TamperIRQHandler()

== Tamper callback ==

    tamp -> app : HAL_RTCEx_Tamper1EventCallback(&hrtc)
    app --> tamp
    end


    group Polling mode

== Configuration and start of active tampers ==

    app -> tamp : HAL_RTCEx_SetActiveTampers(&hrtc, &sTamper1)
    note right
    Pass "RTC_ATAMP_INTERRUPT_DISABLE" as an argument in the "RTC_ActiveTampersTypeDef" structure.
    end note
    tamp --> app : HAL_OK


== Set the seeds ==

    app -> tamp : HAL_RTCEx_SetActiveSeed(&hrtc, &p_values)
    tamp --> app: HAL_OK

== Tamper polling ==

    app -> tamp: HAL_RTCEx_PollForTamperEvent(&hrtc, Tamper, Timeout)
    tamp --> app : HAL_OK
    end

== Stop the active tampers ==

    app -> tamp : HAL_RTCEx_DeactivateActiveTampers(&hrtc)
    tamp --> app: HAL_OK

@enduml

Related examples in HAL2

Example Name

Description

example_hal_tamp_active_detect

The example illustrates the active tamper detection mode. This mode uses a continuous comparison between a tamper output and input generated by a pseudorandom number generator. In case of mismatch between the two signals, a tamper event is then triggered and the tamper backup registers are erased.


HAL TAMPER monotonic counters

HAL1 Sequence Diagrams

HAL2 Sequence Diagrams

@startuml

participant Application as app
participant "Tamper Driver" as tamp

==  Monotonic Counter  ==

    app -> tamp : HAL_RTCEx_MonotonicCounterIncrement()
    tamp --> app: HAL_OK

    app -> tamp : HAL_RTCEx_MonotonicCounterGet()
    tamp --> app : value

@enduml

@startuml

participant Application as app
participant "Tamper Driver" as tamp

==  Monotonic Counter  ==

    app -> tamp : HAL_TAMP_MONOTONIC_IncrementCounter()
    tamp --> app: HAL_OK

    app -> tamp : HAL_TAMP_MONOTONIC_GetCounter()
    tamp --> app : value

@enduml


HAL TAMPER Backup registers

HAL1 Sequence Diagrams

HAL2 Sequence Diagrams

@startuml

participant Application as app
participant "Tamper Driver" as tamp

== Program and retrieve a value  ==

    app -> tamp : HAL_RTCEx_BKUPWrite(&hrtc, BackupRegister, Data)

    app -> tamp : HAL_RTCEx_BKUPRead(&hrtc, BackupRegister)
    tamp --> app : value

@enduml

@startuml

participant Application as app
participant "Tamper Driver" as tamp

== Program and retrieve a value  ==

    app -> tamp : HAL_TAMP_WriteBackupRegisterValue(backup_register, value)

    app -> tamp : HAL_TAMP_ReadBackupRegisterValue(backup_register)
    tamp --> app : value

@enduml

Related examples in HAL2

Example Name

Description

example_hal_tamp_erase_backup_registers

The examples demonstrates the tamper detection feature, used to protect sensitive data from external attacks. It configures an external tamper in passive mode which is ultra-low power edge or level detection. Pressing the user button generates a tamper detection event which erases the TAMP backup registers, written at the beginning.


HAL TAMPER device secrets

HAL1 Sequence Diagrams

HAL2 Sequence Diagrams

@startuml

participant Application as app
participant "Tamper Driver" as tamp

== Configure the erase of the Device Secrets  ==

    app -> tamp : void HAL_RTCEx_BKUPBlock_Disable(hrtc)
    tamp --> app: HAL_OK

    app -> tamp : void HAL_RTCEx_BKUPBlock_Enable(hrtc)
    tamp --> app: HAL_OK

|||
|||

== Erase device ==

    app -> tamp : HAL_RTCEx_BKUPErase()
    tamp --> app: HAL_OK

== Hardware Bootkey ==

    app -> tamp : HAL_RTCEx_LockBootHardwareKey
    tamp --> app: HAL_OK

@enduml

@startuml

participant Application as app
participant "Tamper Driver" as tamp

== Device secrets access  ==

    app -> tamp : HAL_TAMP_UnblockDeviceSecretsAccess()
    tamp --> app: HAL_OK

    app -> tamp : HAL_TAMP_BlockDeviceSecretsAccess()
    tamp --> app: HAL_OK

    app -> tamp : HAL_TAMP_IsBlockedDeviceSecretsAccess()
    tamp --> app : status

== Erase device ==

    app -> tamp : HAL_TAMP_EraseDeviceSecrets()
    tamp --> app: HAL_OK

== Hardware Bootkey ==

    app -> tamp : HAL_TAMP_EnableHardwareBootkeyBlock
    tamp --> app: HAL_OK

    app -> tamp : HAL_TAMP_IsEnabledHardwareBootkeyBlock
    tamp --> app: status

@enduml